/* For detailed instructions, see README file */


OPTIONS SOURCE MACROGEN SYMBOLGEN MPRINT COMPRESS=YES REUSE=YES SORTSIZE= MAX;




/*=========================================*/
/*Select path where files are saved*/
libname OP "INSERT PATH";
/*Select path to save logs*/
%let LOG_PATH= INSERT PATH\Table7.log;
options dlcreatedir; 
%PUT &LOG_PATH;
/*=========================================*/






proc printto log="&LOG_PATH" new;
run;



ODS GRAPHICS OFF;
ODS NORESULTS;
ODS SELECT NONE;
FOOTNOTE " ";
ODS TITLE " ";
/*=========================================*/
/*=========================================*/


data Trade_Data;
set OP.OPRA_Pseudo ;

IF MISSING(DMM_IDENTITY)=0 & DMM_IDENTITY IN 
("Citadel",
"Susquehanna"
"Wolverine",
"Dash"
) 
THEN DO 
PFOF_IND=1; 
PFOF_DMM="YES";
END;

ELSE DO;
PFOF_IND=0; 
PFOF_DMM="NO";
END;



IF S_VOL<=5 THEN SMALL=PUT("YES_SMALL",$12.); ELSE SMALL=PUT("NO_LARGE",$12.);
IF AUCTION_IND=1 THEN AUCTION=PUT("YES_AUCTION",$12.); ELSE AUCTION=PUT("NO_LOB",$12.);



IF DMMP_IND=1										THEN LABEL_1=PUT("DMMP",$12.); else LABEL_1=PUT("Non-DMMP",$12.);
IF PFOF_DMM="YES" 									THEN LABEL_2=PUT("PFOF",$12.); 	else LABEL_2=PUT("Non-PFOF",$12.);


IF AUCTION_IND=1 		& PFOF_DMM="YES" 			THEN LABEL_2=PUT("PFOF Auction",$12.); 
ELSE IF AUCTION_IND=1 	& PFOF_DMM="NO" 			THEN LABEL_2=PUT("Non-PFOF Auction",$12.); 
IF AUCTION_IND=0 		& PFOF_DMM="YES" 			THEN LABEL_2=PUT("PFOF Continuous",$12.);
IF AUCTION_IND=0 		& PFOF_DMM="NO" 			THEN LABEL_2=PUT("Non-PFOF Continuous",$12.);


 
ELSE IF AUCTION_IND=0 	& DIRECTED_OF="YES" 			THEN LABEL_3=PUT("DOF Continuous",$12.); 
IF AUCTION_IND=0 		& DIRECTED_OF="NO"  			THEN LABEL_3=PUT("Non-DOF Continuous",$12.); 
ELSE IF AUCTION_IND=1 	& DIRECTED_OF="YES" 			THEN LABEL_3=PUT("DOF Auction",$12.); 
IF AUCTION_IND=1		& DIRECTED_OF="NO"  			THEN LABEL_3=PUT("Non-DOF Auction",$12.); 


IF S_VOL<=5											THEN LABEL_4=PUT("LE5",$12.); else LABEL_4=PUT("GE5",$12.);


IF S_VOL<=5			& DMMP_IND=1				THEN LABEL_5=PUT("DMMP-LE5",$12.); 
IF S_VOL<=5			& DMMP_IND=0				THEN LABEL_5=PUT("Non-DMMP-LE5",$12.); 
IF S_VOL>5			& DMMP_IND=1				THEN LABEL_5=PUT("DMMP-GE5",$12.); 
IF S_VOL>5			& DMMP_IND=0				THEN LABEL_5=PUT("Non-DMMP-GE5",$12.); 



IF S_VOL<=5			& DMMP_IND=1				THEN LABEL_6=PUT("PFOF-LE5",$12.); 
IF S_VOL<=5			& DMMP_IND=0				THEN LABEL_6=PUT("Non-PFOF-LE5",$12.); 
IF S_VOL>5			& DMMP_IND=1				THEN LABEL_6=PUT("PFOF-GE5",$12.); 
IF S_VOL>5			& DMMP_IND=0				THEN LABEL_6=PUT("Non-PFOF-GE5",$12.);

IF DMMP_IND=1 THEN DIRECTED_OF=PUT("YES",$3.); ELSE DIRECTED_OF=PUT("NO",$3.);




KEEP D_VOL PFOF_IND AUCTION_IND DMMP_IND S_VOL PFOF_DMM SMALL AUCTION DIRECTED_OF;

run;




proc tabulate data=Trade_Data  format=10.2 OUT=MEANS_PFOF(rename=(D_VOL_PctSum_0_D_VOL=PCTSUM_ALL));

VAR  D_VOL;
CLASS PFOF_DMM;

TABLES  
PFOF_DMM*D_VOL*PCTSUM;
RUN;

data MEANS_PFOF;
	set MEANS_PFOF;
	drop _page_ _table_ _TYPE_;
run;



proc tabulate data=Trade_Data  format=10.2 OUT=MEANS_PFOF_AUCTION(rename=(D_VOL_PctSum_00_D_VOL=PCTSUM_ALL));

VAR  D_VOL;
CLASS PFOF_DMM AUCTION;

TABLES  
PFOF_DMM*D_VOL*AUCTION*PCTSUM;
RUN;

data MEANS_PFOF_AUCTION;
	set MEANS_PFOF_AUCTION;
	drop _page_ _table_ _TYPE_;
run;


proc transpose data=MEANS_PFOF_AUCTION out=MEANS_PFOF_AUCTION_T; by PFOF_DMM; id AUCTION;run;




proc tabulate data=Trade_Data  format=10.2 OUT=MEANS_PFOF_AUCTION_SIZE(rename=(D_VOL_PctSum_000_D_VOL=PCTSUM_ALL));

VAR  D_VOL;
CLASS PFOF_DMM AUCTION SMALL;

TABLES  
PFOF_DMM*D_VOL*AUCTION*SMALL*PCTSUM;
RUN;

data MEANS_PFOF_AUCTION_SIZE;
	set MEANS_PFOF_AUCTION_SIZE;
	drop _page_ _table_ _TYPE_;
run;


proc transpose data=MEANS_PFOF_AUCTION_SIZE out=MEANS_PFOF_AUCTION_SIZE_T; by PFOF_DMM; id SMALL AUCTION;run;




proc tabulate data=Trade_Data  format=10.2 OUT=MEANS_DOF(rename=(D_VOL_PctSum_0_D_VOL=PCTSUM_ALL));

VAR  D_VOL;
CLASS DIRECTED_OF;

TABLES  
DIRECTED_OF*D_VOL*PCTSUM;
RUN;

data MEANS_DOF;
	set MEANS_DOF;
	drop _page_ _table_ _TYPE_;
run;



proc tabulate data=Trade_Data  format=10.2 OUT=MEANS_DOF_AUCTION(rename=(D_VOL_PctSum_00_D_VOL=PCTSUM_ALL));

VAR  D_VOL;
CLASS DIRECTED_OF AUCTION;

TABLES  
DIRECTED_OF*D_VOL*AUCTION*PCTSUM;
RUN;

data MEANS_DOF_AUCTION;
	set MEANS_DOF_AUCTION;
	drop _page_ _table_ _TYPE_;
run;


proc transpose data=MEANS_DOF_AUCTION out=MEANS_DOF_AUCTION_T; by DIRECTED_OF; id AUCTION;run;




proc tabulate data=Trade_Data  format=10.2 OUT=MEANS_DOF_AUCTION_SIZE(rename=(D_VOL_PctSum_000_D_VOL=PCTSUM_ALL));

VAR  D_VOL;
CLASS DIRECTED_OF AUCTION SMALL;

TABLES  
DIRECTED_OF*D_VOL*AUCTION*SMALL*PCTSUM;
RUN;

data MEANS_DOF_AUCTION_SIZE;
	set MEANS_DOF_AUCTION_SIZE;
	drop _page_ _table_ _TYPE_;
run;


proc transpose data=MEANS_DOF_AUCTION_SIZE out=MEANS_DOF_AUCTION_SIZE_T; by DIRECTED_OF; id SMALL AUCTION;run;







PROC SQL;
	CREATE TABLE PFOF_VOLUMES
	AS SELECT
	A.PFOF_DMM AS LABEL,
	A.PCTSUM_ALL AS PCTSUM_ALL,
	B.YES_AUCTION AS AUCTION,
	B.NO_LOB AS Continuous,
	C.YES_SMALLYES_AUCTION AS SMALL_AUCTION,
	C.NO_LARGEYES_AUCTION AS LARGE_AUCTION,
	C.YES_SMALLNO_LOB AS SMALL_LOB,
	C.NO_LARGENO_LOB AS LARGE_LOB

	FROM
	Means_pfof A INNER JOIN
	Means_pfof_auction_T B
	ON A.PFOF_DMM=B.PFOF_DMM
	INNER JOIN
	Means_pfof_auction_size_t C
	ON A.PFOF_DMM=C.PFOF_DMM;
QUIT;



PROC SORT DATA=PFOF_VOLUMES; BY DESCENDING LABEL;RUN;




PROC SQL;
	CREATE TABLE DMMP_VOLUMES
	AS SELECT
	A.DIRECTED_OF AS LABEL,
	A.PCTSUM_ALL AS PCTSUM_ALL,
	B.YES_AUCTION AS AUCTION,
	B.NO_LOB AS Continuous,
	C.YES_SMALLYES_AUCTION AS SMALL_AUCTION,
	C.NO_LARGEYES_AUCTION AS LARGE_AUCTION,
	C.YES_SMALLNO_LOB AS SMALL_LOB,
	C.NO_LARGENO_LOB AS LARGE_LOB

	FROM
	Means_DOF A INNER JOIN
	Means_DOF_auction_T B
	ON A.DIRECTED_OF=B.DIRECTED_OF
	INNER JOIN
	Means_DOF_auction_size_t C
	ON A.DIRECTED_OF=C.DIRECTED_OF;
QUIT;



PROC SORT DATA=DMMP_VOLUMES; BY DESCENDING LABEL;RUN;

DATA COMBINED;
	SET PFOF_VOLUMES DMMP_VOLUMES;

	if _N_<=2;

RUN;





/*=========================================*/
ODS GRAPHICS OFF;
ODS RESULTS;
ODS SELECT ALL;
ODS TITLE "TABLE 7: PFOF Volume (Pseudo Data) - Panel A ";
FOOTNOTE "This table presents distribution and regression results for PFOF versus Non-PFOF option
 volume using pseudo OPRA data.";
PROC REPORT data= Combined;
columns
LABEL

PCTSUM_ALL
AUCTION
Continuous

SMALL_AUCTION
SMALL_LOB

LARGE_AUCTION
LARGE_LOB



;


	DEFINE LABEL / DISPLAY "Variable" format =$168.;
	DEFINE PCTSUM_ALL / DISPLAY "All" format =8.2;
	DEFINE Continuous / DISPLAY "Continuous" format =8.2;
	DEFINE AUCTION / DISPLAY "AUCTION" format =8.2;
	DEFINE SMALL_LOB / DISPLAY "SMALL-Continuous" format =8.2;
	DEFINE SMALL_AUCTION / DISPLAY "SMALL-AUCTION" format =8.2;
	DEFINE LARGE_LOB / DISPLAY "LARGE_LOB" format =8.2;
	DEFINE LARGE_AUCTION / DISPLAY "LARGE_AUCTION" format =8.2;




run;

/*=========================================*/
FOOTNOTE " ";
ODS TITLE " ";


ODS GRAPHICS OFF;
ODS NORESULTS;
ODS SELECT NONE;
























proc sort data=OP.OPRA_Pseudo OUT=EXCHANGE (KEEP=SENDER DMMP_IND) NODUPKEY; BY SENDER;RUN;


data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);
KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY DMMP_IND PFOF_IND;
RUN;
PROC SORT DATA=TRADES_DATA_ALL NODUPKEY OUT=DMM_ASSIGNMENT (KEEP=DMM_IDENTITY SENDER SYMBOL_ONLY PFOF_IND); BY DMM_IDENTITY SENDER SYMBOL_ONLY;RUN;
proc sort nodupkey data=TRADES_DATA_ALL out=dates(keep=date) ;by date;run;

/*===========================================*/
proc sql;                  
  create table dates as    
    select A.date,b.sender, b.symbol_only 
                           
    from dates A              
        , DMM_ASSIGNMENT B    ;       
quit;  
/*===========================================*/



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;



PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;


DATA Input_all_exch;
	SET PCTSUM_VOL;
RUN;
PROC SORT DATA=Input_all_exch; BY SYMBOL_ONLY;RUN;







data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);

IF S_VOL<=5;

KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;


PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;




DATA Input_all_exch_l5;
	SET PCTSUM_VOL;
RUN;















data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);

IF S_VOL>5;

KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;



PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;




DATA Input_all_exch_g5;
	SET PCTSUM_VOL;
RUN;












data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF AUCTION_IND=0;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);
KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;


option notes source source2;


PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;




DATA Input_all_exch_lob;
	SET PCTSUM_VOL;
RUN;








data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);

IF S_VOL<=5 & AUCTION_IND=0;

KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;


option notes source source2;


PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;



DATA Input_all_exch_lob_l5;
	SET PCTSUM_VOL;
RUN;












data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);

IF S_VOL>5 & AUCTION_IND=0;

KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;


option notes source source2;


PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;


DATA Input_all_exch_lob_g5;
	SET PCTSUM_VOL;
RUN;















data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF AUCTION_IND=1;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);
KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;





PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;


option notes source source2;


PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;



DATA Input_all_exch_auc;
	SET PCTSUM_VOL;
RUN;












data TRADES_DATA_ALL;
set OP.OPRA_Pseudo;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);

IF S_VOL<=5 & AUCTION_IND=1;

KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;


option notes source source2;


PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;


DATA Input_all_exch_auc_l5;
	SET PCTSUM_VOL;
RUN;













data TRADES_DATA_ALL;
set  OP.OPRA_Pseudo;

IF MISSING(DMM_IDENTITY)=1 THEN DMM_IDENTITY= PUT("NO-DMM",$32.);

IF S_VOL>5 & AUCTION_IND=1;

KEEP D_VOL S_VOL SYMBOL_ONLY DATE SENDER DMM_IDENTITY;
RUN;



PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT 
	A.D_VOL,
	A.S_VOL,
	
	B.DATE, B.SYMBOL_ONLY, B.SENDER




	FROM TRADES_DATA_ALL A RIGHT JOIN DATES B
	ON
	A.DATE = B.DATE & A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;
DATA TABLE TRADES_DATA_ALL;
	SET TRADES_DATA_ALL;
	IF D_VOL=. THEN D_VOL=0;
	IF S_VOL=. THEN S_VOL=0;
RUN;




PROC SQL;
	CREATE TABLE TRADES_DATA_ALL
	AS SELECT SUM(D_VOL) AS D_VOL, SUM(S_VOL) AS S_VOL, SYMBOL_ONLY,DATE, COUNT(*) AS COUNTS, SENDER
	FROM TRADES_DATA_ALL
	GROUP BY SYMBOL_ONLY,DATE, SENDER;
QUIT;



PROC SORT DATA=TRADES_DATA_ALL;BY DATE SYMBOL_ONLY;RUN;
proc tabulate data=TRADES_DATA_ALL format=8.2 OUT=PCTSUM_VOL (RENAME=(D_VOL_PctSum_0_D_VOL=PCTSUM_DVOL S_VOL_PctSum_0_S_VOL=PCTSUM_SVOL
												  COUNTS_PctSum_0_COUNTS=PCTSUM_TRADES)) ;

class DATE SYMBOL_ONLY SENDER;
VAR D_VOL S_VOL COUNTS;

table  SENDER*D_VOL*(PCTSUM)
	   SENDER*S_VOL*(PCTSUM)
	   SENDER*COUNTS*(PCTSUM);
BY DATE SYMBOL_ONLY;
 RUN;



PROC SQL;
	CREATE TABLE PCTSUM_VOL
	AS SELECT A.*, B.DMM_IDENTITY, B.PFOF_IND
	FROM PCTSUM_VOL A LEFT JOIN DMM_ASSIGNMENT  B
	ON A.SENDER=B.SENDER & A.SYMBOL_ONLY=B.SYMBOL_ONLY;
QUIT;




DATA Input_all_exch_auc_g5;
	SET PCTSUM_VOL;
RUN;





PROC SQL;
	CREATE TABLE INPUT_ALL_EXCH
	AS SELECT A.*, B.DMMP_IND
	FROM INPUT_ALL_EXCH A INNER JOIN EXCHANGE B
	ON A.SENDER=B.SENDER;
QUIT;

DATA INPUT_ALL_EXCH;
	SET INPUT_ALL_EXCH;

CHARDATE = put(date,date9.);


RUN;


PROC SQL;
	CREATE TABLE INPUT_ALL_EXCH_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM INPUT_ALL_EXCH
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE INPUT_ALL_EXCH_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,
	CHARDATE, SYMBOL_ONLY
	FROM INPUT_ALL_EXCH_D1
	GROUP BY CHARDATE;
QUIT;



PROC SQL;
	CREATE TABLE Input_all_exch_g5
	AS SELECT A.*, B.DMMP_IND
	FROM Input_all_exch_g5 A INNER JOIN EXCHANGE B
	ON A.SENDER=B.SENDER;
QUIT;

DATA Input_all_exch_g5;
	SET Input_all_exch_g5;


CHARDATE = put(date,date9.);


RUN;



PROC SQL;
	CREATE TABLE INPUT_ALL_EXCH_G5_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM INPUT_ALL_EXCH_G5
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE INPUT_ALL_EXCH_G5_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	CHARDATE, SYMBOL_ONLY
	FROM INPUT_ALL_EXCH_G5_D1
	GROUP BY CHARDATE;
QUIT;





PROC SQL;
	CREATE TABLE Input_all_exch_L5
	AS SELECT A.*, B.DMMP_IND
	FROM Input_all_exch_L5 A INNER JOIN EXCHANGE B
	ON A.SENDER=B.SENDER;
QUIT;

DATA Input_all_exch_L5;
	SET Input_all_exch_L5;


CHARDATE = put(date,date9.);


RUN;




PROC SQL;
	CREATE TABLE INPUT_ALL_EXCH_L5_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,
	CHARDATE, SYMBOL_ONLY
	FROM INPUT_ALL_EXCH_L5
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE INPUT_ALL_EXCH_L5_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM INPUT_ALL_EXCH_L5_D1
	GROUP BY CHARDATE;
QUIT;








PROC SQL;
	CREATE TABLE Input_all_exch_lob
	AS SELECT A.*, B.DMMP_IND
	FROM Input_all_exch_lob A INNER JOIN EXCHANGE B
	ON A.SENDER=B.SENDER;
QUIT;
DATA Input_all_exch_lob;
	SET Input_all_exch_lob;

CHARDATE = put(date,date9.);


RUN;





PROC SQL;
	CREATE TABLE Input_all_exch_lob_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_lob
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE Input_all_exch_lob_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_lob_D1
	GROUP BY CHARDATE;
QUIT;






PROC SQL;
	CREATE TABLE Input_all_exch_lob_L5
	AS SELECT A.*, B.DMMP_IND
	FROM Input_all_exch_lob_L5 A INNER JOIN EXCHANGE B
	ON A.SENDER=B.SENDER;
QUIT;
DATA Input_all_exch_lob_L5;
	SET Input_all_exch_lob_L5;

CHARDATE = put(date,date9.);


RUN;



PROC SQL;
	CREATE TABLE Input_all_exch_lob_L5_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_lob_L5
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE Input_all_exch_lob_L5_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_lob_L5_D1
	GROUP BY CHARDATE;
QUIT;





PROC SQL;
	CREATE TABLE Input_all_exch_lob_G5
	AS SELECT A.*, B.DMMP_IND
	FROM Input_all_exch_lob_G5 A INNER JOIN EXCHANGE B
	ON A.SENDER=B.SENDER;
QUIT;
DATA Input_all_exch_lob_G5;
	SET Input_all_exch_lob_G5;

CHARDATE = put(date,date9.);


RUN;




PROC SQL;
	CREATE TABLE Input_all_exch_lob_G5_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_lob_G5
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE Input_all_exch_lob_G5_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_lob_G5_D1
	GROUP BY CHARDATE;
QUIT;








proc sort data=OP.OPRA_Pseudo(WHERE=(AUCTION_IND=1)) OUT=EXCHANGE_AUCTIONS (KEEP=AUCTION_IND SENDER DMMP_IND) NODUPKEY; BY SENDER;RUN;

PROC SQL;
	CREATE TABLE Input_all_exch_auc
	AS SELECT A.*,B.DMMP_IND
	FROM Input_all_exch_auc A INNER JOIN EXCHANGE_AUCTIONS B
	ON A.SENDER=B.SENDER;
QUIT;


DATA Input_all_exch_auc;
	SET Input_all_exch_auc;

CHARDATE = put(date,date9.);


RUN;



PROC SQL;
	CREATE TABLE Input_all_exch_auc_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_auc
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE Input_all_exch_auc_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_auc_D1
	GROUP BY CHARDATE;
QUIT;







PROC SQL;
	CREATE TABLE Input_all_exch_auc_l5
	AS SELECT A.*,B.DMMP_IND
	FROM Input_all_exch_auc_l5 A INNER JOIN EXCHANGE_AUCTIONS B
	ON A.SENDER=B.SENDER;
QUIT;

DATA Input_all_exch_auc_l5;
	SET Input_all_exch_auc_l5;

CHARDATE = put(date,date9.);


RUN;
PROC SQL;
	CREATE TABLE Input_all_exch_auc_L5_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_auc_L5
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE Input_all_exch_auc_L5_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_auc_L5_D1
	GROUP BY CHARDATE;
QUIT;







PROC SQL;
	CREATE TABLE Input_all_exch_auc_g5
	AS SELECT A.*,B.DMMP_IND
	FROM Input_all_exch_auc_g5 A INNER JOIN EXCHANGE_AUCTIONS B
	ON A.SENDER=B.SENDER;
QUIT;

DATA Input_all_exch_auc_G5;
	SET Input_all_exch_auc_G5;

CHARDATE = put(date,date9.);


RUN;





PROC SQL;
	CREATE TABLE Input_all_exch_auc_G5_D1
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_auc_G5
	GROUP BY SYMBOL_ONLY;
QUIT;


PROC SQL;
	CREATE TABLE Input_all_exch_auc_G5_D2
	AS SELECT
	PFOF_IND - MEAN(PFOF_IND) AS PFOF_IND,SENDER,
	DMMP_IND - MEAN(DMMP_IND) AS DMMP_IND,
	PCTSUM_TRADES - MEAN(PCTSUM_TRADES) AS PCTSUM_TRADES,
	PCTSUM_DVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_DVOL,
	PCTSUM_SVOL - MEAN(PCTSUM_DVOL) AS PCTSUM_SVOL,

	CHARDATE, SYMBOL_ONLY
	FROM Input_all_exch_auc_G5_D1
	GROUP BY CHARDATE;
QUIT;




ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND
/noint SOLUTION

;


quit;



PROC SORT DATA=INPUT_ALL_EXCH;BY SYMBOL_ONLY;RUN;
ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=INPUT_ALL_EXCH;
ABSORB SYMBOL_ONLY;

model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND



/solution noint; 
run;
quit;
data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates_clus;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;



run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	 IF find(parameter, "SYMBOL_ONLY")=0;
	 	IF parameter ="ABS_DELTA" then parameter="Abs_Delta";





run;


data Regression_1;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_1
	as select a.*, b.Probt
	from Regression_1 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_1; by n type;run;



ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=Input_all_exch_L5_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;



PROC SORT DATA=INPUT_ALL_EXCH_L5;BY SYMBOL_ONLY;RUN;
ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=Input_all_exch_L5;
ABSORB SYMBOL_ONLY;

model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND


/solution NOINT; 
run;
quit;



data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates_clus;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;



run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	 IF find(parameter, "SYMBOL_ONLY")=0;
	 	IF parameter ="ABS_DELTA" then parameter="Abs_Delta";





run;


data Regression_2;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_2
	as select a.*, b.Probt
	from Regression_2 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_2; by n type;run;









ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_G5_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;

PROC SORT DATA=Input_all_exch_G5; BY SYMBOL_ONLY;RUN;
ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=Input_all_exch_G5;
ABSORB SYMBOL_ONLY;

model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND


/solution NOINT; 
run;
quit;



data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates_clus;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;



run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	 IF find(parameter, "SYMBOL_ONLY")=0;
	 	IF parameter ="ABS_DELTA" then parameter="Abs_Delta";





run;


data Regression_3;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_3
	as select a.*, b.Probt
	from Regression_3 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_3; by n type;run;














PROC SQL;
	CREATE TABLE Regression_Combined_All
	AS SELECT A.VALUE AS VALUE_R1,A.PROBT AS PROBT_R1, A.N as N_R1, A.PARAMETER AS PARAMETER_R1,A.TYPE AS TYPE_R1,
	D.VALUE AS VALUE_R2,D.PROBT AS PROBT_R2, D.N as N_R2, D.PARAMETER AS PARAMETER_R2,D.TYPE AS TYPE_R2,
	E.VALUE AS VALUE_R3,E.PROBT AS PROBT_R3, E.N as N_R3, E.PARAMETER AS PARAMETER_R3,E.TYPE AS TYPE_R3
	

	FROM REGRESSION_1 A
	FULL JOIN REGRESSION_2 D
	ON A.PARAMETER=D.PARAMETER & A.TYPE=D.TYPE
	FULL JOIN REGRESSION_3 E
	ON A.PARAMETER=E.PARAMETER & A.TYPE=E.TYPE
	
;
QUIT;



proc sort data=Regression_Combined_All; BY N_R1 TYPE_R1;RUN;


DATA Regression_Combined_All;
	SET Regression_Combined_All;
	BY N_R1 TYPE_R1;


IF parameter_R1 = "PFOF_IND" & Type_R1="E" then VARIABLE = PUT("PFOF",$48.);
IF parameter_R1 = "PFOF_IND" & Type_R1="S" then VARIABLE = PUT(" ",$48.);

IF parameter_R1 = "DMMP_IND" & Type_R1="E" then VARIABLE = PUT("DMMP",$48.);
IF parameter_R1 = "DMMP_IND" & Type_R1="S" then VARIABLE = PUT(" ",$48.);




IF parameter_R1 = "Rsq" & Type_R1="E" THEN  VARIABLE = PUT("\multicolumn{1}{l}{R\textsuperscript{2}}",$48.);





IF parameter_R1 = "NObs"  THEN  VARIABLE = PUT("NObs",$48.);




RUN;




DATA Regression_Combined_All;
	SET Regression_Combined_All;
	BY N_R1 TYPE_R1;

	
	

	

	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R1) then do;
	
			if    PROBT_R1<0.01 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\threeS"),$28.);
			else if PROBT_R1<0.05 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\twoS"),$28.);
			else if PROBT_R1<0.1 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\oneS"),$28.);
			else if PROBT_R1>0.1 & Type_R1="E" then VALUE_CHAR_R1=PUT(PUT(Value_R1,8.3),$CHAR28.);
	end;
	
	

	
	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R2) then do;
	
			if    PROBT_R2<0.01 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\threeS"),$48.);
			else if PROBT_R2<0.05 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\twoS"),$48.);
			else if PROBT_R2<0.1 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\oneS"),$48.);
			else if PROBT_R2>0.1 & Type_R2="E" then VALUE_CHAR_R2=PUT(PUT(Value_R2,8.3),$CHAR48.);
	end;

	
	

	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R3) then do;
	
			if    PROBT_R3<0.01 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\threeS"),$28.);
			else if PROBT_R3<0.05 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\twoS"),$28.);
			else if PROBT_R3<0.1 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\oneS"),$28.);
			else if PROBT_R3>0.1 & Type_R3="E" then VALUE_CHAR_R3=PUT(PUT(Value_R3,8.3),$CHAR28.);
	end;
	
	

	




		if Type_R1="S" then do;
			
				IF NOT MISSING(Value_R1) THEN
				VALUE_CHAR_R1=PUT(CATS("(",PUT(Value_R1,8.3),")"),$28.);
				IF NOT MISSING(Value_R2) THEN
				VALUE_CHAR_R2=PUT(CATS("(",PUT(Value_R2,8.3),")"),$28.);
				IF NOT MISSING(Value_R3) THEN
				VALUE_CHAR_R3=PUT(CATS("(",PUT(Value_R3,8.3),")"),$28.);
			end;
			
	
	 


if VARIABLE in ("RSq", "Rsq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") then do;
	

VALUE_CHAR_R1=PUT(PUT(Value_R1,8.3),$28.);
VALUE_CHAR_R2=PUT(PUT(Value_R2,8.3),$28.);
VALUE_CHAR_R3=PUT(PUT(Value_R3,8.3),$28.);


END;




run;




data fixed_effects;
  do i= 1 to 1;
  output;
  end;
run;

data fixed_effects;
	set fixed_effects;

		if _n_=1 then do; VARIABLE = PUT("Stock Fixed",$48.); N_R1=23; TYPE_R1="Z";end;
		
run;

DATA Regression_Combined_All;
	SET Regression_Combined_All fixed_effects;

	IF VARIABLE = "Stock Fixed" THEN DO;
		VALUE_CHAR_R3=put("Yes",$28.);
		VALUE_CHAR_R2=put("Yes",$28.);
		VALUE_CHAR_R1=put("Yes",$28.);
		END;
run;



DATA Regression_Combined_All;
	set  Regression_Combined_All;

	IF TYPE_R1="S" THEN  VARIABLE = " ";
RUN;




ODS GRAPHICS OFF;
ODS RESULTS;
ODS SELECT ALL;
ODS TITLE "TABLE 7: PFOF Volume (Pseudo Data) - Panel B - All Trades";
FOOTNOTE "This table presents distribution of volume and regression results for PFOF versus Non-PFOF option
 volume using pseudo OPRA data.";
/*=========================================*/
PROC REPORT data=Regression_Combined_All;
columns
variable 
value_char_R1
value_char_R2 
value_char_R3


;


	DEFINE VARIABLE / DISPLAY "Variable" format =$168.;
	DEFINE value_char_R1  /DISPLAY "All" format =$168.;
	DEFINE value_char_R2  /DISPLAY "Contract <=5" format =$168.;
	DEFINE value_char_R3  /DISPLAY "Contract >5" format =$168.;

run;
FOOTNOTE " ";
ODS TITLE " ";



ODS GRAPHICS OFF;
ODS NORESULTS;
ODS SELECT NONE;
/*=========================================*/


ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_AUC_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;
PROC SORT DATA=INPUT_ALL_EXCH_AUC; BY SYMBOL_ONLY;RUN;
ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=INPUT_ALL_EXCH_AUC;

ABSORB SYMBOL_ONLY;
model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND


/solution NOINT; 
run;
quit;
data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates_clus;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;



run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	 IF find(parameter, "SYMBOL_ONLY")=0;
	 	IF parameter ="ABS_DELTA" then parameter="Abs_Delta";





run;


data Regression_1;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_1
	as select a.*, b.Probt
	from Regression_1 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;




proc sort data=Regression_1; by n type;run;


ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_AUC_L5_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;
PROC SORT DATA=INPUT_ALL_EXCH_AUC_L5; BY SYMBOL_ONLY;RUN;


ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=Input_all_exch_AUC_L5;

ABSORB SYMBOL_ONLY;
model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND

/solution NOINT; 
run;
quit;



data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates_clus;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;



run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	 IF find(parameter, "SYMBOL_ONLY")=0;
	 	IF parameter ="ABS_DELTA" then parameter="Abs_Delta";





run;


data Regression_2;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_2
	as select a.*, b.Probt
	from Regression_2 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_2; by n type;run;






ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_AUC_G5_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;
PROC SORT DATA=INPUT_ALL_EXCH_AUC_G5; BY SYMBOL_ONLY;RUN;

ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=Input_all_exch_AUC_G5;
ABSORB SYMBOL_ONLY;
model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND
/solution ; 
run;
quit;



data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;



run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;




run;


data Regression_3;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_3
	as select a.*, b.Probt
	from Regression_3 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_3; by n type;run;














PROC SQL;
	CREATE TABLE Regression_Combined_AUC
	AS SELECT A.VALUE AS VALUE_R1,A.PROBT AS PROBT_R1, A.N as N_R1, A.PARAMETER AS PARAMETER_R1,A.TYPE AS TYPE_R1,
	D.VALUE AS VALUE_R2,D.PROBT AS PROBT_R2, D.N as N_R2, D.PARAMETER AS PARAMETER_R2,D.TYPE AS TYPE_R2,
	E.VALUE AS VALUE_R3,E.PROBT AS PROBT_R3, E.N as N_R3, E.PARAMETER AS PARAMETER_R3,E.TYPE AS TYPE_R3
	

	FROM REGRESSION_1 A
	FULL JOIN REGRESSION_2 D
	ON A.PARAMETER=D.PARAMETER & A.TYPE=D.TYPE
	FULL JOIN REGRESSION_3 E
	ON A.PARAMETER=E.PARAMETER & A.TYPE=E.TYPE
	
;
QUIT;



proc sort data=Regression_Combined_AUC; BY N_R1 TYPE_R1;RUN;


DATA Regression_Combined_AUC;
	SET Regression_Combined_AUC;
	BY N_R1 TYPE_R1;


IF parameter_R1 = "PFOF_IND" & Type_R1="E" then VARIABLE = PUT("PFOF",$48.);
IF parameter_R1 = "PFOF_IND" & Type_R1="S" then VARIABLE = PUT("StdPFOF IND",$48.);

IF parameter_R1 = "DMMP_IND" & Type_R1="E" then VARIABLE = PUT("DMMP",$48.);
IF parameter_R1 = "DMMP_IND" & Type_R1="S" then VARIABLE = PUT("StdDMMPIND",$48.);

IF PARAMETER_R1 = "/*PCTSUM_MCOUNTS*/" & Type_R1="E" then VARIABLE = PUT("Mult. Prints",$48.);
IF PARAMETER_R1 = "/*PCTSUM_MCOUNTS*/" & Type_R1="S" then VARIABLE = PUT("StdMult. Prints",$48.);

IF parameter_R1 = "/*PCTSUM_DOLLAR*/" & Type_R1="E" then VARIABLE = PUT("PFOF(%)",$48.);
IF parameter_R1 = "/*PCTSUM_DOLLAR*/" & Type_R1="S" then VARIABLE = PUT("StdPFOF(%)",$48.);



IF parameter_R1 = "VIX" & Type_R1="E" then VARIABLE = PUT("VIX",$48.);
IF parameter_R1 = "VIX" & Type_R1="S" then VARIABLE = PUT("StdVIX",$48.);







IF parameter_R1 = "Rsq" & Type_R1="E" THEN  VARIABLE = PUT("R-Sq",$48.);





IF parameter_R1 = "Rsq"  THEN  VARIABLE = PUT("RSq",$48.);
IF parameter_R1 = "NObs"  THEN  VARIABLE = PUT("NObs",$48.);




RUN;



DATA Regression_Combined_AUC;
	SET Regression_Combined_AUC;
	BY N_R1 TYPE_R1;

	
	

	

	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R1) then do;
	
			if    PROBT_R1<0.01 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\threeS"),$28.);
			else if PROBT_R1<0.05 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\twoS"),$28.);
			else if PROBT_R1<0.1 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\oneS"),$28.);
			else if PROBT_R1>0.1 & Type_R1="E" then VALUE_CHAR_R1=PUT(PUT(Value_R1,8.3),$CHAR28.);
	end;
	
	

	
	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R2) then do;
	
			if    PROBT_R2<0.01 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\threeS"),$48.);
			else if PROBT_R2<0.05 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\twoS"),$48.);
			else if PROBT_R2<0.1 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\oneS"),$48.);
			else if PROBT_R2>0.1 & Type_R2="E" then VALUE_CHAR_R2=PUT(PUT(Value_R2,8.3),$CHAR48.);
	end;

	
	

	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R3) then do;
	
			if    PROBT_R3<0.01 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\threeS"),$28.);
			else if PROBT_R3<0.05 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\twoS"),$28.);
			else if PROBT_R3<0.1 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\oneS"),$28.);
			else if PROBT_R3>0.1 & Type_R3="E" then VALUE_CHAR_R3=PUT(PUT(Value_R3,8.3),$CHAR28.);
	end;
	
	

	




		if Type_R1="S" then do;
			
				IF NOT MISSING(Value_R1) THEN
				VALUE_CHAR_R1=PUT(CATS("(",PUT(Value_R1,8.3),")"),$28.);
				IF NOT MISSING(Value_R2) THEN
				VALUE_CHAR_R2=PUT(CATS("(",PUT(Value_R2,8.3),")"),$28.);
				IF NOT MISSING(Value_R3) THEN
				VALUE_CHAR_R3=PUT(CATS("(",PUT(Value_R3,8.3),")"),$28.);
			end;
			
	
	 


if VARIABLE in ("RSq", "Rsq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") then do;
	

VALUE_CHAR_R1=PUT(PUT(Value_R1,8.3),$28.);
VALUE_CHAR_R2=PUT(PUT(Value_R2,8.3),$28.);
VALUE_CHAR_R3=PUT(PUT(Value_R3,8.3),$28.);


END;




run;




data fixed_effects;
  do i= 1 to 1;
  output;
  end;
run;

data fixed_effects;
	set fixed_effects;

		if _n_=1 then do; VARIABLE = PUT("Stock Fixed",$48.); N_R1=23; TYPE_R1="Z";end;
		
run;

DATA Regression_Combined_AUC;
	SET Regression_Combined_AUC fixed_effects;


	IF VARIABLE = "Stock Fixed" THEN DO;
		VALUE_CHAR_R3=put("Yes",$28.);
		VALUE_CHAR_R2=put("Yes",$28.);
		VALUE_CHAR_R1=put("Yes",$28.);
		END;
run;



DATA Regression_Combined_AUC;
	set  Regression_Combined_AUC;

	IF TYPE_R1="S" THEN  VARIABLE = " ";
RUN;



/*=========================================*/
ODS GRAPHICS OFF;
ODS RESULTS;
ODS SELECT ALL;
ODS TITLE "TABLE 7: PFOF Volume (Pseudo Data) Panel C - Auctions";
FOOTNOTE "This table presents distribution of volume and regression results for PFOF versus Non-PFOF option
 volume using pseudo OPRA data.";
PROC REPORT data=Regression_Combined_AUC;
columns
variable 
value_char_R1
value_char_R2 
value_char_R3


;


	DEFINE VARIABLE / DISPLAY "Variable" format =$168.;
	DEFINE value_char_R1  /DISPLAY "All" format =$168.;
	DEFINE value_char_R2  /DISPLAY "Contract <=5" format =$168.;
	DEFINE value_char_R3  /DISPLAY "Contract >5" format =$168.;

run;

FOOTNOTE " ";
ODS TITLE " ";


ODS GRAPHICS OFF;
ODS NORESULTS;
ODS SELECT NONE;




/*=======================================================================================================*/
/*Continuous ONLY*/

ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_LOB_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;
PROC SORT DATA=INPUT_ALL_EXCH_LOB; BY SYMBOL_ONLY;RUN;
ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=INPUT_ALL_EXCH_LOB;
ABSORB SYMBOL_ONLY;
model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND

/solution NOINT; 
run;
quit;
data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		

run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates_clus;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	 IF find(parameter, "SYMBOL_ONLY")=0;
	 	IF parameter ="ABS_DELTA" then parameter="Abs_Delta";




run;


data Regression_1;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_1
	as select a.*, b.Probt
	from Regression_1 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_1; by n type;run;


ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_LOB_L5_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;
PROC SORT DATA=INPUT_ALL_EXCH_LOB_L5; BY SYMBOL_ONLY;RUN;


ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=Input_all_exch_LOB_L5;
ABSORB SYMBOL_ONLY;
model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND
/solution NOINT; 
run;
quit;



data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates_clus;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	 IF find(parameter, "SYMBOL_ONLY")=0;
	 	IF parameter ="ABS_DELTA" then parameter="Abs_Delta";





run;


data Regression_2;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_2
	as select a.*, b.Probt
	from Regression_2 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_2; by n type;run;







ODS OUTPUT ParameterEstimates = ParameterEstimates_clus;
proc surveyreg data=INPUT_ALL_EXCH_LOB_G5_D1;
cluster SYMBOL_ONLY CHARDATE ;
 
model 
PCTSUM_DVOL=


PFOF_IND
DMMP_IND

/NOINT
;


quit;
PROC SORT DATA=INPUT_ALL_EXCH_LOB_G5; BY SYMBOL_ONLY;RUN;


ODS OUTPUT ParameterEstimates = ParameterEstimates;
ODS OUTPUT FitStatistics = FitStatistics;
ODS OUTPUT NObs = NObs;
proc glm namelen=64  data=Input_all_exch_LOB_G5;

ABSORB SYMBOL_ONLY;
model 
PCTSUM_DVOL=

PFOF_IND
DMMP_IND

/solution ; 
run;
quit;



data ParameterEstimates_e (keep=parameter value Type);
	set ParameterEstimates;
	rename Estimate=value;
	Type="E";
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

		



run;

data FitStatistics (keep=parameter value Type);
	set FitStatistics;
	
	rename  RSquare=value;
	
	parameter = "Rsq";
	type ="E";
    IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;

			 
run;


data ParameterEstimates_p(keep=parameter probt);
	set ParameterEstimates;

 	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;



run;


data nobs(keep=value type parameter);
	set nobs;
	type = "E";
	parameter = "NObs";
	rename NObsRead = value;

	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
	if label="Number of Observations Used";
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;


	 

run;

data ParameterEstimates_s(keep=parameter value Type);;
	set ParameterEstimates_clus;
	Type ="S";
	rename StdErr = Value;
	IF find(parameter, "SYMBOL_ONLY")=0;
	IF find(parameter, "CHARDATE")=0;
		IF parameter ="ABS_DELTA" then parameter="Abs_Delta";
			IF find(parameter, "SENDER")=0;
			IF find(parameter, "sender")=0;




run;


data Regression_3;
	set ParameterEstimates_e parameterEstimates_s FitStatistics nobs;
		


	if parameter="PFOF_IND" then n=1;
	if parameter="/*PCTSUM_MCOUNTS*/" then n=2;
	if parameter="DMMP_IND" then n=3;


	if parameter="Rsq" then n=25;
	if parameter ="NObs" then n=26; 

run;

proc sql;
	create table Regression_3
	as select a.*, b.Probt
	from Regression_3 A left join ParameterEstimates_p B
	ON A.parameter = b.parameter;
quit;



proc sort data=Regression_3; by n type;run;














PROC SQL;
	CREATE TABLE Regression_Combined_LOB
	AS SELECT A.VALUE AS VALUE_R1,A.PROBT AS PROBT_R1, A.N as N_R1, A.PARAMETER AS PARAMETER_R1,A.TYPE AS TYPE_R1,
	D.VALUE AS VALUE_R2,D.PROBT AS PROBT_R2, D.N as N_R2, D.PARAMETER AS PARAMETER_R2,D.TYPE AS TYPE_R2,
	E.VALUE AS VALUE_R3,E.PROBT AS PROBT_R3, E.N as N_R3, E.PARAMETER AS PARAMETER_R3,E.TYPE AS TYPE_R3
	

	FROM REGRESSION_1 A
	FULL JOIN REGRESSION_2 D
	ON A.PARAMETER=D.PARAMETER & A.TYPE=D.TYPE
	FULL JOIN REGRESSION_3 E
	ON A.PARAMETER=E.PARAMETER & A.TYPE=E.TYPE
	
;
QUIT;



proc sort data=Regression_Combined_LOB; BY N_R1 TYPE_R1;RUN;


DATA Regression_Combined_LOB;
	SET Regression_Combined_LOB;
	BY N_R1 TYPE_R1;


IF parameter_R1 = "PFOF_IND" & Type_R1="E" then VARIABLE = PUT("PFOF",$48.);
IF parameter_R1 = "PFOF_IND" & Type_R1="S" then VARIABLE = PUT("StdPFOF IND",$48.);

IF parameter_R1 = "DMMP_IND" & Type_R1="E" then VARIABLE = PUT("DMMP",$48.);
IF parameter_R1 = "DMMP_IND" & Type_R1="S" then VARIABLE = PUT("StdDMMPIND",$48.);

IF PARAMETER_R1 = "/*PCTSUM_MCOUNTS*/" & Type_R1="E" then VARIABLE = PUT("Mult. Prints",$48.);
IF PARAMETER_R1 = "/*PCTSUM_MCOUNTS*/" & Type_R1="S" then VARIABLE = PUT("StdMult. Prints",$48.);

IF parameter_R1 = "/*PCTSUM_DOLLAR*/" & Type_R1="E" then VARIABLE = PUT("PFOF(%)",$48.);
IF parameter_R1 = "/*PCTSUM_DOLLAR*/" & Type_R1="S" then VARIABLE = PUT("StdPFOF(%)",$48.);



IF parameter_R1 = "VIX" & Type_R1="E" then VARIABLE = PUT("VIX",$48.);
IF parameter_R1 = "VIX" & Type_R1="S" then VARIABLE = PUT("StdVIX",$48.);







IF parameter_R1 = "Rsq" & Type_R1="E" THEN  VARIABLE = PUT("R-Sq",$48.);





IF parameter_R1 = "Rsq"  THEN  VARIABLE = PUT("RSq",$48.);
IF parameter_R1 = "NObs"  THEN  VARIABLE = PUT("NObs",$48.);




RUN;




DATA Regression_Combined_LOB;
	SET Regression_Combined_LOB;
	BY N_R1 TYPE_R1;

	
	

	

	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R1) then do;
	
			if    PROBT_R1<0.01 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\threeS"),$28.);
			else if PROBT_R1<0.05 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\twoS"),$28.);
			else if PROBT_R1<0.1 & Type_R1="E" then VALUE_CHAR_R1=PUT(CATS(PUT(Value_R1,8.3),"\oneS"),$28.);
			else if PROBT_R1>0.1 & Type_R1="E" then VALUE_CHAR_R1=PUT(PUT(Value_R1,8.3),$CHAR28.);
	end;
	
	

	
	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R2) then do;
	
			if    PROBT_R2<0.01 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\threeS"),$48.);
			else if PROBT_R2<0.05 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\twoS"),$48.);
			else if PROBT_R2<0.1 & Type_R2="E" then VALUE_CHAR_R2=PUT(CATS(PUT(Value_R2,8.3),"\oneS"),$48.);
			else if PROBT_R2>0.1 & Type_R2="E" then VALUE_CHAR_R2=PUT(PUT(Value_R2,8.3),$CHAR48.);
	end;

	
	

	if VARIABLE not in ("RSq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") & NOT MISSING(Value_R3) then do;
	
			if    PROBT_R3<0.01 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\threeS"),$28.);
			else if PROBT_R3<0.05 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\twoS"),$28.);
			else if PROBT_R3<0.1 & Type_R3="E" then VALUE_CHAR_R3=PUT(CATS(PUT(Value_R3,8.3),"\oneS"),$28.);
			else if PROBT_R3>0.1 & Type_R3="E" then VALUE_CHAR_R3=PUT(PUT(Value_R3,8.3),$CHAR28.);
	end;
	
	

	




		if Type_R1="S" then do;
			
				IF NOT MISSING(Value_R1) THEN
				VALUE_CHAR_R1=PUT(CATS("(",PUT(Value_R1,8.3),")"),$28.);
				IF NOT MISSING(Value_R2) THEN
				VALUE_CHAR_R2=PUT(CATS("(",PUT(Value_R2,8.3),")"),$28.);
				IF NOT MISSING(Value_R3) THEN
				VALUE_CHAR_R3=PUT(CATS("(",PUT(Value_R3,8.3),")"),$28.);
			end;
			
	
	 


if VARIABLE in ("RSq", "Rsq","NObs","Avg. Inv Mills - N.AUC","Avg. Inv Mills - AUC") then do;
	

VALUE_CHAR_R1=PUT(PUT(Value_R1,8.3),$28.);
VALUE_CHAR_R2=PUT(PUT(Value_R2,8.3),$28.);
VALUE_CHAR_R3=PUT(PUT(Value_R3,8.3),$28.);


END;




run;




data fixed_effects;
  do i= 1 to 1;
  output;
  end;
run;

data fixed_effects;
	set fixed_effects;
		if _n_=1 then do; VARIABLE = PUT("Stock Fixed",$48.); N_R1=23; TYPE_R1="Z";end;
		
run;

DATA Regression_Combined_LOB;
	SET Regression_Combined_LOB fixed_effects;


	IF VARIABLE = "Stock Fixed" THEN DO;
		VALUE_CHAR_R3=put("Yes",$28.);
		VALUE_CHAR_R2=put("Yes",$28.);
		VALUE_CHAR_R1=put("Yes",$28.);
		END;
run;



DATA Regression_Combined_LOB;
	set  Regression_Combined_LOB;

	IF TYPE_R1="S" THEN  VARIABLE = " ";
RUN;




ODS GRAPHICS OFF;
ODS RESULTS;
ODS SELECT ALL;
ODS TITLE "TABLE 7: PFOF Volume (Pseudo Data) - Panel D - Continuous Trading";
FOOTNOTE "This table presents distribution of volume and regression results for PFOF versus Non-PFOF option
 volume using pseudo OPRA data.";
/*=========================================*/
PROC REPORT data=Regression_Combined_LOB;
columns
variable 
value_char_R1
value_char_R2 
value_char_R3


;


	DEFINE VARIABLE / DISPLAY "Variable" format =$168.;
	DEFINE value_char_R1  /DISPLAY "All" format =$168.;
	DEFINE value_char_R2  /DISPLAY "Contract <=5" format =$168.;
	DEFINE value_char_R3  /DISPLAY "Contract >5" format =$168.;

run;

FOOTNOTE " ";
ODS TITLE " ";



ODS GRAPHICS OFF;
ODS NORESULTS;
ODS SELECT NONE;
/*=========================================*/








proc printto log=log;
run;

